package com.example.kotlinlearningproject.ui.activity

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.enableEdgeToEdge
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.kotlinlearningproject.R
import com.example.kotlinlearningproject.databinding.ActivitySecondBinding
import com.example.kotlinlearningproject.helper.BitmapBinder
import com.example.kotlinlearningproject.utils.Const

class SecondActivity : ComponentActivity() {
    private lateinit var binding: ActivitySecondBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        binding = ActivitySecondBinding.inflate(layoutInflater)
        setContentView(binding.root)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        initFromIntent()
    }

    private fun  initFromIntent() {
        val bundle = intent.extras
        val bitmapBinder = bundle?.getBinder(Const.INTENT_IMAGE) as BitmapBinder
        val bitmap = bitmapBinder.getBitmap()
//        val bitmap = intent.getParcelableExtra(Const.INTENT_IMAGE) as Bitmap?
        // 将Bitmap设置给ImageView
        binding.imgTest.setImageBitmap(bitmap)
    }
}